<script lang="jsx" setup>
import dayjs from 'dayjs';
import { computed, nextTick, ref } from 'vue';

const commonSearchRef = ref(null);
const tableRef = ref(null);
const searchParams = ref({
  moduleNo: null,
  lotId: null,
  pnlId: null,
  time: null,
  hasPnl: null
});

const searchFormList = [
  {
    type: 'input',
    key: 'moduleNo',
    label: '生产型号',
    span: 24,
    md: 12,
    lg: 10,
    xl: 8,
    xxl: 6,
    placeholder: '请输入生产型号',
    showTime: true
  },
  {
    type: 'input',
    key: 'lotId',
    label: '批次号',
    span: 24,
    md: 12,
    lg: 10,
    xl: 8,
    xxl: 6,
    placeholder: '请输入批次号',
    showTime: true
  },
  {
    type: 'select',
    key: 'hasPnl',
    label: '是否有码',
    placeholder: '请选择是否有码',
    span: 24,
    md: 12,
    lg: 8,
    xl: 8,
    xxl: 6,
    selectOptions: [
      {
        label: '有码',
        value: 1
      },
      {
        label: '无码',
        value: 2
      }
    ]
  },
  {
    type: 'input',
    key: 'pnlId',
    label: ' PNL码',
    span: 24,
    md: 12,
    lg: 10,
    xl: 8,
    xxl: 6,
    placeholder: '请输入PNL码',
    showTime: true
  },

  {
    type: 'dateRangePicker',
    key: 'time',
    label: '日　　期',
    span: 24,
    md: 12,
    lg: 10,
    xl: 8,
    xxl: 6,
    showTime: true // 显示时分秒选择
  }
];

const searchData = computed(() => {
  const params = {
    ...searchParams.value
  };
  if (searchParams.value?.time?.[0]) {
    params.startTime = dayjs(searchParams.value.time[0]).format('YYYY-MM-DD HH:mm:ss');
    params.endTime = dayjs(searchParams.value.time[1]).format('YYYY-MM-DD HH:mm:ss');
  }
  delete params.time;
  return params;
});

// 表格数据
const column = [
  {
    key: 'dataIndex',
    dataIndex: 'dataIndex',
    title: '序号',
    fixed: 'left',
    width: 70,
    align: 'center',
    checked: true,
    ellipsis: true
  },

  {
    key: 'moduleNo',
    dataIndex: 'moduleNo',
    title: ' 生产型号',
    width: 160,
    align: 'center',
    checked: true,
    ellipsis: true,
    fixed: 'left'
  },
  {
    key: 'lotId',
    dataIndex: 'lotId',
    title: ' 批次号',
    width: 140,
    align: 'center',
    checked: true,
    ellipsis: true,
    fixed: 'left'
  },
  {
    key: 'pnlId',
    dataIndex: 'pnlId',
    title: ' PNL码',
    width: 140,
    align: 'center',
    checked: true,
    ellipsis: true,
    fixed: 'left'
  },
  {
    key: 'readCodeTime',
    dataIndex: 'readCodeTime',
    title: '进站时间',
    width: 150,
    align: 'center',
    checked: true,
    ellipsis: true,
    fixed: 'left'
  },

  {
    key: 'mainEqpId',
    dataIndex: 'mainEqpId',
    title: '设备编号',
    align: 'center',
    width: 100,
    checked: true,
    ellipsis: true,
    fixed: 'left'
  },
  {
    key: 'itemName1',
    dataIndex: 'itemName1',
    title: '批次产量记录 PNL',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName2',
    dataIndex: 'itemName2',
    title: '开机时间累积 h',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName3',
    dataIndex: 'itemName3',
    title: '总产量记录 PNL',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName4',
    dataIndex: 'itemName4',
    title: '全线工作时间累积 h',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName5',
    dataIndex: 'itemName5',
    title: '用电量累积 kW·h',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName6',
    dataIndex: 'itemName6',
    title: '自来水用量累积 m³',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName7',
    dataIndex: 'itemName7',
    title: 'DI水用量累积 m³',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName8',
    dataIndex: 'itemName8',
    title: '入板输送速度_实时值',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName9',
    dataIndex: 'itemName9',
    title: '磨板至出板输送速度_实时值 m/min',
    align: 'center',
    width: 250,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName10',
    dataIndex: 'itemName10',
    title: '磨板至出板输送速度_设置值 m/min',
    align: 'center',
    width: 250,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName11',
    dataIndex: 'itemName11',
    title: '磨辘摇摆频率_实时值 Hz',
    align: 'center',
    width: 200,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName12',
    dataIndex: 'itemName12',
    title: '磨辘摇摆频率_设置值 Hz',
    align: 'center',
    width: 200,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName13',
    dataIndex: 'itemName13',
    title: '中粗化1温度_实时值 ℃',
    align: 'center',
    width: 200,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName14',
    dataIndex: 'itemName14',
    title: '中粗化2温度_实时值 ℃',
    align: 'center',
    width: 200,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName15',
    dataIndex: 'itemName15',
    title: '酸洗温度_实时值 ℃',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName16',
    dataIndex: 'itemName16',
    title: '热风吹干1温度_实时值 ℃',
    align: 'center',
    width: 200,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName17',
    dataIndex: 'itemName17',
    title: '热风吹干2温度_实时值 ℃',
    align: 'center',
    width: 200,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName18',
    dataIndex: 'itemName18',
    title: '中粗化1温度_设置值 ℃',
    align: 'center',
    width: 180,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName19',
    dataIndex: 'itemName19',
    title: '中粗化2温度_设置值 ℃',
    align: 'center',
    width: 180,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName20',
    dataIndex: 'itemName20',
    title: '酸洗温度_设置值 ℃',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName21',
    dataIndex: 'itemName21',
    title: '热风吹干1温度_设置值 ℃',
    align: 'center',
    width: 200,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName22',
    dataIndex: 'itemName22',
    title: '热风吹干2温度_设置值 ℃',
    align: 'center',
    width: 200,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName23',
    dataIndex: 'itemName23',
    title: '中粗化1上喷压力_实时值 kg/cm²',
    align: 'center',
    width: 250,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName24',
    dataIndex: 'itemName24',
    title: '中粗化1下喷压力_实时值 kg/cm²',
    align: 'center',
    width: 250,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName25',
    dataIndex: 'itemName25',
    title: '中粗化2上喷压力_实时值 kg/cm²',
    align: 'center',
    width: 250,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName26',
    dataIndex: 'itemName26',
    title: '中粗化2下喷压力_实时值 kg/cm²',
    align: 'center',
    width: 250,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName27',
    dataIndex: 'itemName27',
    title: '强风吹干1压力_实时值 kPa',
    align: 'center',
    width: 200,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName28',
    dataIndex: 'itemName28',
    title: '强风吹干2压力_实时值 kPa',
    align: 'center',
    width: 200,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName29',
    dataIndex: 'itemName29',
    title: '强风吹干3&4压力_实时值 kPa',
    align: 'center',
    width: 250,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName30',
    dataIndex: 'itemName30',
    title: '强风吹干5&6压力_实时值 kPa',
    align: 'center',
    width: 250,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName31',
    dataIndex: 'itemName31',
    title: '中粗化1喷淋压力_实时值 kg/cm²',
    align: 'center',
    width: 250,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName32',
    dataIndex: 'itemName32',
    title: '中粗化2喷淋压力_实时值 kg/cm²',
    align: 'center',
    width: 250,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName33',
    dataIndex: 'itemName33',
    title: '中粗化1喷淋压力_设置值 kg/cm²',
    align: 'center',
    width: 250,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName34',
    dataIndex: 'itemName34',
    title: '中粗化2喷淋压力_设置值 kg/cm²',
    align: 'center',
    width: 250,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName35',
    dataIndex: 'itemName35',
    title: '上磨刷一当前电流 A',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName36',
    dataIndex: 'itemName36',
    title: '下磨刷一当前电流 A',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName37',
    dataIndex: 'itemName37',
    title: '上磨刷二当前电流 A',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName38',
    dataIndex: 'itemName38',
    title: '下磨刷二当前电流 A',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName39',
    dataIndex: 'itemName39',
    title: '上磨刷一电流设置 A',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName40',
    dataIndex: 'itemName40',
    title: '下磨刷一电流设置 A',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName41',
    dataIndex: 'itemName41',
    title: '上磨刷二电流设置 A',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'itemName42',
    dataIndex: 'itemName42',
    title: '下磨刷二电流设置 A',
    align: 'center',
    width: 150,
    checked: true,
    ellipsis: true
  },
  {
    key: 'dateTime',
    dataIndex: 'dateTime',
    title: '创建时间',
    width: 150,
    align: 'center',
    checked: true,
    ellipsis: true
  }
];

function search() {
  tableRef.value.getData(1);
}

function reset() {
  nextTick(() => {
    searchParams.value = {
      moduleNo: null,
      lotId: null,
      pnlId: null,
      time: null,
      hasPnl: null
    };
    search();
  });
}
</script>

<template>
  <div
    class="code-whitelist-page jl-main-page min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto"
  >
    <CommonSearch
      ref="commonSearchRef"
      v-model:searchParams="searchParams"
      :form-list="searchFormList"
      :is-search="true"
      @search="search"
      @reset="reset"
    ></CommonSearch>

    <Table
      ref="tableRef"
      v-model:searchParams="searchData"
      :column="column"
      :show-row-selection="false"
      :auto-generate-uuid="true"
      :scroll="{ y: 'auto' }"
      is-init-get-data
      url="eap/EapEqpTrace2/selectYuZhouOutQcl1"
    ></Table>
  </div>
</template>

<style lang="scss" scoped></style>
